package cn.stylefeng.guns.sys.modular.system.controller;

import cn.stylefeng.guns.sys.modular.system.model.DdBxdDetail;
import cn.stylefeng.guns.sys.modular.system.model.DdBxdlParam;
import cn.stylefeng.guns.sys.modular.system.service.DDService;
import cn.stylefeng.roses.core.reqres.response.ResponseData;
import cn.stylefeng.roses.core.reqres.response.SuccessResponseData;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;

@Controller
@RequestMapping("ddbxd")
public class DDbxdController {

    private static final Logger log= LoggerFactory.getLogger(DDbxdController.class);
    private String PREFIX = "/modular/system/btyBxd";

    @Resource
    private DDService dDService;


    @RequestMapping("")
    public String toIndex(){
        return PREFIX + "/ddbxd.html";
    }

    @RequestMapping("/ddbxdkj")
    public String toDdbxdkj(){
        return PREFIX + "/ddbxdkj.html";
    }

    @RequestMapping("/list")
    @ResponseBody
    public ResponseData list(DdBxdlParam param) throws Exception {
        ResponseData responseData = dDService.listBxdsNew(param);
        return  responseData;
    }
    @RequestMapping("/listkj")
    @ResponseBody
    public ResponseData listkj(DdBxdlParam param) throws Exception {
        ResponseData responseData = dDService.listBxdsNewkj(param);
        return  responseData;
    }

    @RequestMapping("/copyBxd")
    @ResponseBody
    public ResponseData copyBxd(DdBxdlParam param) throws Exception {
        ResponseData responseData = dDService.copyBxd(param);
        return  responseData;
    }

    @RequestMapping("/btnCopyFinish")
    @ResponseBody
    public ResponseData btnCopyFinish(DdBxdlParam param) throws Exception {
        ResponseData responseData = dDService.btnCopyFinish(param);
        return responseData;
    }

    @RequestMapping("/toDetail")
    public String toDetail(String id){
        /*DdBxdDetail detail = dDService.getById(id);
        m.addAttribute("data",detail);*/
        return  PREFIX + "/ddbxd_detail.html";
    }

    @RequestMapping("/detail/{id}")
    @ResponseBody
    public ResponseData ddbxdDetail(@PathVariable String id) throws Exception {
        DdBxdDetail detail = dDService.getById(id);
        return SuccessResponseData.success(detail);
    }

    @RequestMapping("/ddbxdSync/{id}")
    @ResponseBody
    public ResponseData ddbxdSync(@PathVariable String id) throws Exception {
        return dDService.ddbxdSync(id);
    }

    @RequestMapping("/queryLastDaysData")
    @ResponseBody
    public ResponseData queryLastDaysData(DdBxdlParam param) throws Exception {
        return dDService.cacheLastDaysData(param);
    }

    @RequestMapping("/test")
    @ResponseBody
    public ResponseData test() throws Exception {
        dDService.autoImportData();
        return SuccessResponseData.success();
    }


    @RequestMapping("/pullFromDingding")
    @ResponseBody
    public ResponseData pullFromDingding(DdBxdlParam param) throws Exception {
        return dDService.pullFromDingding(param);
    }

    /**
     * 会计下载数据
     * @param param
     * @return
     * @throws Exception
     */
    @RequestMapping("/pullFromDingdingKj")
    @ResponseBody
    public ResponseData pullFromDingdingKj(DdBxdlParam param) throws Exception {
        return dDService.pullFromDingdingKj(param);
    }
}
